{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# 设置中文字体，确保中文正常显示\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "# 如果是Mac本, 不支持SimHei的时候, 可以修改为 'Microsoft YaHei' 或者 'Arial Unicode MS'\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "data = pd.read_csv(r'C:\\Users\\61016.000\\Desktop\\tut2.0\\data\\raw\\train.csv')\n",
    "data.describe().T"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-20T02:27:16.303302Z",
     "start_time": "2025-07-20T02:27:16.289545Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#数据读取\n",
    "data = pd.read_csv(r'../../data/raw/train.csv')\n",
    "data= pd.get_dummies(data)\n",
    "data.drop(['OverTime_No', 'Over18_Y','EmployeeNumber'], axis=1, inplace=True)\n",
    "y=data.iloc[:,-1]\n",
    "x=data.iloc[:,0:-1]\n"
   ],
   "id": "d2d3f72ddf294510",
   "outputs": [],
   "execution_count": 39
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "data.info()",
   "id": "e36d320df71a16b7",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "import seaborn as sns\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "def plot_feature_heatmap(df, figsize=(40, 20), annot=True, cmap=\"coolwarm\"):\n",
    "    \"\"\"绘制特征相关性热区图\"\"\"\n",
    "    # 计算相关系数\n",
    "    corr_matrix = df.corr()\n",
    "\n",
    "    # 创建画布\n",
    "    plt.figure(figsize=figsize)\n",
    "\n",
    "    # 绘制热区图\n",
    "    heatmap = sns.heatmap(\n",
    "        corr_matrix,\n",
    "        annot=annot,          # 是否在单元格中显示数值\n",
    "        fmt=\".2f\",            # 数值格式\n",
    "        cmap=cmap,            # 颜色映射\n",
    "        square=True,          # 使热图为正方形\n",
    "        linewidths=.5,        # 网格线宽度\n",
    "        vmin=-1, vmax=1,      # 颜色映射的取值范围\n",
    "        cbar_kws={\"shrink\": .8}  # 颜色条大小\n",
    "    )\n",
    "\n",
    "    # 设置标题\n",
    "    plt.title('feature', fontsize=15)\n",
    "\n",
    "    # 调整布局\n",
    "    plt.tight_layout()\n",
    "\n",
    "    return plt\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    # 生成样本数据\n",
    "    df = data\n",
    "\n",
    "    # 打印数据集基本信息\n",
    "    print(\"数据集前5行:\")\n",
    "    print(df.head())\n",
    "    print(\"\\n数据集形状:\", df.shape)\n",
    "\n",
    "    # 绘制并显示热区图\n",
    "    plt = plot_feature_heatmap(df)\n",
    "\n",
    "    # 也可以保存图片\n",
    "    plt.savefig('feature_heatmap.png', dpi=300, bbox_inches='tight')"
   ],
   "id": "e35ef0e001e8b3cd",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
